/********************************************************************************/
/*                                                                              */
/*                      Pooled private loans and bond data                      */
/*   Uncertainty and macro data that correspond to the beginning of the fiscal  */
/*               quarter in   which the loan/bond is issued                     */
/********************************************************************************/

clear all
set more off
capture log close

*Select the appropriate folder for the project
cd "..."

*Load data set
use "..."


*Volatility quartile
xtile vol_quartile= impvol365, nq(4)
label var vol_quartile "Uncertainty Rank"

label var	impvol365	"Price Uncertainty"
label var	pricefutby100	"Futures Price /100"
label var	l_impvol365	"Price Uncertainty"
label var	l_pricefutby100	"Futures Price /100"
label var	price_futures	"Futures Price"
label var	size	"Size"
label var	atq	"Assets ($ Millions)"
label var	mtb	"Market-to-Book"
label var	leverage	"Leverage"
label var	ebitda2at	"EBITDA"
label var	logmaturity	"LogMaturity"
label var	maturity_years	"Maturity (years)"
label var	loan2at	"Offering Amount"
label var	term_spread	"Term Spread"
label var	termspread	"Term Spread"
label var	perfpricing	"Performance Pricing"
label var	rated	"Rated"
label var	invgrade_comp	"Investment Grade"

label var	credit_spread "Credit Spread"
label var	creditspread "Credit Spread"
label var	vix "VIX"
label var 	futret3m "Oil Return"
label var	spret3m "SP500 Return"
label var 	futret6m "Oil Return"
label var	spret6m "SP500 Return"

label var 	fincov "Financial Covenants"
label var	percov	"P Inclusion"
label var	capcov	"C Inclusion"
label var	numofpercov	"P Intensity"
label var	numofcapcov	"C Intensity"
label var	spreads "Spread"

destring(gvkey), gen(gvkey1)

*Create performance covenants for loans and bonds
gen perfcov=1 if percov==1 | fixed_charge_coverage_is== "Y"
replace perfcov=0 if perfcov==.
label var	perfcov	"Performance Cov."



generate loanpurp=.
replace loanpurp=1 if dealpurpose==  "Acquis. line"
replace loanpurp=2 if dealpurpose== "Corp. purposes"
replace loanpurp=3 if dealpurpose== "Debt Repay."
replace loanpurp=4 if dealpurpose== "Takeover"
replace loanpurp=5 if dealpurpose== "Work. cap."
replace loanpurp=0 if dealpurpose!=""  & loanpurp==.
label define lnpp 0 "Other" 1 "Acquis. line" 2 "Corp. purposes" 3 "Debt Repay." 4 "Takeover"  5 "Work. cap."
label values loanpurp lnpp

label define privateloan 0 "Bonds" 1 "Loans"
label values privateloan privateloan

label define ig 0 "Non-Investment Grade" 1 "Investment Grade"
label values invgrade_comp ig

egen volsd=sd(impvol365)
display volsd


/*****************************************************************************/
/*                            Summary Statistics                             */
/*****************************************************************************/

*Summary stats all variables
eststo clear              
quietly estpost tabstat impvol365 price_futures term_spread atq size mtb leverage ebitda2at rated invgrade_comp maturity_years loan2at spreads, s(mean sd N) columns(s)
eststo s11
quietly estpost ttest impvol365 price_futures term_spread atq size mtb leverage ebitda2at rated invgrade_comp maturity_years loan2at spreads, by(privateloan) unequal
eststo s12

esttab s11 s12, cells("mean(fmt(2) label(All)) mu_1(fmt(2) label(Bonds)) mu_2(fmt(2) label(Loans)) t(fmt(2) label(T-DIF))") nonumber label 
esttab s11 s12 using "G:\My Drive\Work\Research\Working_Papers\Oil_Prices_Covenant\Stata\Tables\sumst.tex", cells("mean(fmt(2) label(All)) mu_1(fmt(2) label(Bonds)) mu_2(fmt(2) label(Loans)) t(fmt(2) label(T-DIF))") nonumber label replace


*Classification of covenants and frequency
gen fixed_charge_coverage_b=1 if fixed_charge_coverage_is=="Y" | fixed_charge_coverage_sub=="Y" 
replace fixed_charge_coverage_b=0 if fixed_charge_coverage_b==. & privateloan==0

eststo s200: estpost tab perfcov
eststo s201: estpost tab perfcov if privateloan==0
eststo s202: estpost tab perfcov if privateloan==1
eststo s21: estpost tab privateloan
eststo s22: estpost tab fixed_charge_coverage_b
eststo s23: estpost tab mincashinterestcoverage 
eststo s24: estpost tab mindebtservicecoverage 
eststo s25: estpost tab minebitda 
eststo s26: estpost tab minfixedchargecoverage
eststo s27: estpost tab mininterestcoverage 
eststo s28: estpost tab maxdebttoebitda 
eststo s29: estpost tab maxseniordebttoebitda 

esttab s200 s201 s202 s21 s22 s23 s24 s25 s26 s27 s28 s29, cell(b pct(fmt(1))) noobs nonumber collabels(none) nolabel

	
*Correlations
quietly estpost corr impvol365 perfcov spreads maturity_years loan2at price_futures term_spread credit_spread vix futret6m spret6m if privateloan==0, matrix
eststo c1
quietly estpost corr impvol365 perfcov spreads maturity_years loan2at price_futures term_spread credit_spread vix futret6m spret6m if privateloan==1, matrix
eststo c2
quietly estpost corr impvol365 perfcov privateloan spreads maturity_years loan2at price_futures term_spread credit_spread vix futret6m spret6m, matrix
eststo c3

esttab c1, not unstack compress noobs nonumber b(2) star(* 0.10 ** 0.05 *** 0.01) label  title("Bonds Sample") 
esttab c2, not unstack compress noobs nonumber b(2) star(* 0.10 ** 0.05 *** 0.01) label title("Loans Sample") 
esttab c3, not unstack compress noobs nonumber b(2) star(* 0.10 ** 0.05 *** 0.01) label title("Correlations") 



/*****************************************************************************/
/*                             Main Regressions                              */
/*****************************************************************************/

eststo clear
****************** Baseline regressions*******************************************
*Main regressions and marginal effects uncertainty

quietly probit perfcov impvol365 pricefutby100 size mtb leverage ebitda2at logmaturity loan2at i.invgrade_comp termspread if privateloan==1, cluster(gvkey) vsquish 
eststo b1, title(Loans) 
quietly margins, dydx(impvol365) coeflegend post
estadd scalar cb0 = _b[impvol365]*volsd*100
eststo b11, title(Loans)

quietly probit perfcov impvol365 pricefutby100 size mtb leverage ebitda2at logmaturity loan2at i.invgrade_comp termspread if privateloan==0, cluster(gvkey) vsquish 
eststo b2, title(Bonds)
quietly margins, dydx(impvol365) coeflegend post
estadd scalar cb0 = _b[impvol365]*volsd*100
eststo b21, title(Bonds)

quietly probit perfcov c.impvol365##i.privateloan pricefutby100 size mtb leverage ebitda2at logmaturity loan2at i.invgrade_comp termspread, cluster(gvkey) vsquish
eststo b3, title(All Firms) 
quietly margins , dydx(impvol365) over(privateloan) coeflegend post
test _b[impvol365:1.privateloan]=_b[impvol365:0bn.privateloan]
estadd scalar cb1 = _b[impvol365:1.privateloan]*volsd*100
estadd scalar cb2 = _b[impvol365:0bn.privateloan]*volsd*100
estadd scalar cb31 = r(chi2) 
estadd scalar pb31= r(p)
eststo b31, title (All)
est restore b3
quietly margins, dydx(impvol365) post
estadd scalar cb0 = _b[impvol365]*volsd*100
eststo b32, title (All)

quietly probit perfcov c.impvol365##i.privateloan pricefutby100 size mtb leverage ebitda2at logmaturity loan2at i.invgrade_comp termspread  if bothgroups==1, cluster(gvkey) vsquish
eststo b4, title(Issued Both) 
quietly margins , dydx(impvol365) over(privateloan) coeflegend post
test _b[impvol365:1.privateloan]=_b[impvol365:0bn.privateloan]
estadd scalar cb1 = _b[impvol365:1.privateloan]*volsd*100
estadd scalar cb2 = _b[impvol365:0bn.privateloan]*volsd*100
estadd scalar cb31 = r(chi2) 
estadd scalar pb31= r(p)
eststo b41, title (Both)
est restore b4
quietly  margins, dydx(impvol365) coeflegend post
estadd scalar cb0 = _b[impvol365]*volsd*100
eststo b42, title (Both)

esttab b2 b1 b3 b4, b(2) star(* 0.10 ** 0.05 *** 0.01)  pr2(2) nobaselevels title("Uncertainty and Debt Covenants") label varwidth(35) mtitles order(*impvol365 *privateloan) 
esttab b21 b11 b31 b41 b32 b42, b(2) noobs z star(* 0.10 ** 0.05 *** 0.01) scalars("cb0 M.E. 1std" "cb2 M.E. 1std Bonds" "cb1 M.E. 1std Loans""cb31 \(\chi^2\) (difference)" "pb31 \(p-\)value (difference)") ///
 sfmt(2 2 2 2 3) mtitles nonumbers title(Average Marginal Effects of Uncertainty) varwidth(35) label 


*Loan sample: Marginal effect of 1 sd increase in volatility 
est restore b1
****Average marginal effect of uncertainty
quietly margins, dydx(impvol365) coeflegend post
*****Average marginal effect of 1 std deviation increase in uncertainty
test 0.07316501*_b[impvol365]=0

*Bond sample: Marginal effect of 1 sd increase in volatility
est restore b2
quietly margins, dydx(impvol365) coeflegend post
test 0.07316501*_b[impvol365]=0

*Full sample
est restore b3
quietly margins , dydx(impvol365) over(privateloan) coeflegend post
test 0.07316501*_b[impvol365:1.privateloan]=0
test 0.07316501*_b[impvol365:0bn.privateloan]=0

*Sample wiht both
est restore b4
quietly margins , dydx(impvol365) over(privateloan) coeflegend post
test 0.07316501*_b[impvol365:1.privateloan]=0
test 0.07316501*_b[impvol365:0bn.privateloan]=0

*****************Controlling for other macro variables in baseline regressions******************

quietly probit perfcov impvol365 pricefutby100 size mtb leverage ebitda2at logmaturity loan2at i.invgrade_comp termspread creditspread vix futret6m spret6m if privateloan==1, cluster(gvkey) vsquish 
eststo m1, title(Loans) 
quietly margins , dydx(impvol365) post
eststo m11, title(Loans)

quietly probit perfcov impvol365 pricefutby100 size mtb leverage ebitda2at logmaturity loan2at i.invgrade_comp termspread creditspread vix futret6m spret6m if privateloan==0, cluster(gvkey) vsquish 
eststo m2, title(Bonds)
quietly margins , dydx(impvol365) post
eststo m21, title(Bonds)

quietly probit perfcov c.impvol365##i.privateloan pricefutby100 size mtb leverage ebitda2at logmaturity loan2at i.invgrade_comp termspread creditspread vix futret6m spret6m, cluster(gvkey) vsquish
eststo m3, title(All Firms) 
quietly margins , dydx(impvol365) over(privateloan) coeflegend post
test _b[impvol365:1.privateloan]=_b[impvol365:0bn.privateloan]
estadd scalar cm31 = r(chi2) 
estadd scalar pm31= r(p)
eststo m31, title (All)


quietly probit perfcov c.impvol365##i.privateloan pricefutby100 size mtb leverage ebitda2at logmaturity loan2at i.invgrade_comp termspread creditspread vix futret6m spret6m if bothgroups==1, cluster(gvkey) vsquish
eststo m4, title(Issued Both) 
quietly margins , dydx(impvol365) over(privateloan) coeflegend post
test _b[impvol365:1.privateloan]=_b[impvol365:0bn.privateloan]
estadd scalar cm41 = r(chi2) 
estadd scalar pm41= r(p)
eststo m41, title (Both)


esttab m2 m1 m3 m4, b(2) star(* 0.10 ** 0.05 *** 0.01)  pr2(2) nobaselevels title("Uncertainty and Debt Covenants Robustness") label varwidth(35) mtitles order(*impvol365 *privateloan) ///
   drop( *.perfpricing numoflenders *.loanpurp)
esttab m21 m11 m31 m41 , b(2) noobs z star(* 0.10 ** 0.05 *** 0.01) scalars("cm31 \(\chi^2\) (difference)" "pm31 \(p-\)value (difference)" cm41  pm41) ///
 sfmt(2 3 2 3) mtitles nonumbers title(Average Marginal Effects of Uncertainty) varwidth(35) label 



*****************Margins plots baseline regression******************


*Loan sample
*Predicted probability of inclusion at various level of uncertainty
est restore b1
quietly margins, at(impvol365=(0.15(0.07)0.5)) 
marginsplot, plotopts(recast(line) lcolor(maroon) lp("_-_")) ytitle("Prob. of Perf. Cov. Inclusion") ciopts(recast(rline) lpattern(dash) lcolor(maroon)) legend(on order(2 "Loans")) name(l1, replace) title("Loans Sample only") nodraw

*Bond sample
est restore b2
quietly margins, at(impvol365=(0.15(0.07)0.5)) 
marginsplot, recast(line) ytitle("Prob. of Perf. Cov. Inclusion") ciopts(recast(rline) lpattern(dash)) legend(on order(2 "Bonds")) name(b1, replace) title("Bonds Sample only")  nodraw


*Full sample interaction
est restore b3
*Produce the shape of the effect of uncertainty between loans and bonds
quietly margins, at(impvol365=(0.15(0.07)0.5)) over(privateloan) 
marginsplot, recast(line) ytitle("Prob. of Perf. Cov. Inclusion") ciopts(recast(rline) lpattern(shortdash)) name(a1, replace) title("Full Sample")  nodraw plot1opts(lp("l")) plot2opts(lp("_-_"))
*Produce the difference between the two curves above and shows how the effect of uncertainty changes 
quietly margins, at(impvol365=(0.15(0.07)0.5)) over(r.privateloan) 
marginsplot, yline(0) recast(line) ytitle("Contrast of Prob. of Inclusion") ciopts(recast(rline) lpattern(shortdash)) name(a2, replace) title("Contrast in Predictive Margins") legend(on order(2 "Loans vs Bonds")) nodraw 
graph combine a1 a2, title("Predictive Margins: Loans vs Bonds (Full Sample)") name(a12, replace) 

*Subsample with both interaction
est restore b4
quietly margins, at(impvol365=(0.15(0.07)0.5)) over(privateloan)
marginsplot, recast(line) ytitle("Prob. of Perf. Cov. Inclusion") ciopts(recast(rline) lpattern(shortdash)) name(c1, replace) title("Firms with Both Securities") nodraw plot1opts(lp("l")) plot2opts(lp("_-_"))
quietly margins, at(impvol365=(0.15(0.07)0.5)) over(r.privateloan) 
marginsplot, yline(0) recast(line) ytitle("Contrast of Prob. of Inclusion") ciopts(recast(rline) lpattern(dash)) name(c2, replace) title("Contrast in Predictive Margins") legend(on order(2 "Loans vs Bonds"))  nodraw
graph combine c1 c2, title("Predictive Margins: Loans vs Bonds (Firms with Both)") name(c12, replace) 


graph combine b1 l1, title("Predictive Margins: Loans and Bonds ", size(medlarge)) name(m1, replace)
graph combine a1 c1, title("Predictive Margins: Loans vs Bonds", size(medlarge)) name(m2, replace) 

graph display l12
graph display a12
graph display c12



/*****************************************************************************/
/*                      Cross- Sectional Regressions                         */
/*****************************************************************************/
*Define all dummy variables such that 1 (yes) is bad and 0 (No) is good
**The point is to show that firms with riskier profile are more affected
*** Riskier profile should be 1 (unrated, junk rating, high leve, etc...)

*Report separate regression for bonds and loans with interaction of cross-sectional variable


/******Interaction with credit rating******/
gen unrated=1-rated
label define cr 1 "Unrated" 0 "Rated"
label values unrated cr

quietly probit perfcov c.impvol365##i.unrated pricefutby100 size mtb leverage ebitda2at logmaturity loan2at i.invgrade_comp termspread if privateloan==1, cluster(gvkey) vsquish 
eststo r1, title(Loans) 
quietly margins , dydx(impvol365) over(unrated) coeflegend post
quietly test _b[impvol365:1.unrated]=_b[impvol365:0bn.unrated]
estadd scalar chisq = r(chi2) 
estadd scalar pchi= r(p)
eststo r11, title(Unrated)
est restore r1
quietly margins unrated , at(impvol365=(0.15(0.07)0.5))
marginsplot, yline(0) name(cr11, replace) nodraw title(Predictive Margins Loans) ytitle("Prob. of Perf. Cov. Inclusion") plot1opts(lp("l") m(o)) plot2opts(lp("--") m(t))

quietly probit perfcov c.impvol365##i.unrated pricefutby100 size mtb leverage ebitda2at logmaturity loan2at i.invgrade_comp termspread if privateloan==0, cluster(gvkey) vsquish 
eststo r2, title(Bonds)
quietly margins , dydx(impvol365) over(unrated) coeflegend post
quietly test _b[impvol365:1.unrated]=_b[impvol365:0bn.unrated]
estadd scalar chisq = r(chi2) 
estadd scalar pchi= r(p)
eststo r21, title(Unrated)
est restore r2
quietly margins unrated , at(impvol365=(0.15(0.07)0.5))
marginsplot, yline(0) name(cr12, replace) nodraw title(Predictive Margins Bonds) ytitle("Prob. of Perf. Cov. Inclusion") plot1opts(lp("l") m(o)) plot2opts(lp("--") m(t))

graph combine cr12 cr11, ycommon name(cr112, replace) nodraw  iscale(*.75) 

/******Interaction with investment grade******/
gen junkr= 1-invgrade_comp
replace junkr=. if rated==0
label define jk 1 "Speculative Grade" 0 "Investment Grade"
label values junkr jk

quietly probit perfcov c.impvol365##i.junkr pricefutby100 size mtb leverage ebitda2at logmaturity loan2at termspread if privateloan==1, cluster(gvkey) vsquish 
eststo i1, title(Loans) 
quietly margins , dydx(impvol365) over(junkr) coeflegend post
test _b[impvol365:1.junkr]=_b[impvol365:0bn.junkr]
estadd scalar chisq = r(chi2) 
estadd scalar pchi= r(p)
eststo i11, title(JunkR )
est restore i1
quietly margins junkr , at(impvol365=(0.15(0.07)0.5))
marginsplot, yline(0) name(ci11, replace) nodraw title(Predictive Margins Loans)  ytitle("Prob. of Perf. Cov. Inclusion") plot1opts(lp("l") m(o)) plot2opts(lp("--") m(t))

quietly probit perfcov c.impvol365##i.junkr pricefutby100 size mtb leverage ebitda2at logmaturity loan2at termspread if privateloan==0, cluster(gvkey) vsquish 
eststo i2, title(Bonds)
quietly margins , dydx(impvol365) over(junkr) coeflegend post
test _b[impvol365:1.junkr]=_b[impvol365:0bn.junkr]
estadd scalar chisq = r(chi2) 
estadd scalar pchi= r(p)
eststo i21, title(JunkR)
est restore i2
quietly margins junkr , at(impvol365=(0.15(0.07)0.5))
marginsplot, yline(0) name(ci12, replace) nodraw title(Predictive Margins Bonds)  ytitle("Prob. of Perf. Cov. Inclusion") plot1opts(lp("l") m(o)) plot2opts(lp("--") m(t))

graph combine ci12 ci11, ycommon name(ci112, replace) nodraw iscale(*.75) 

/******Interaction with Leverage******/	
*Leverage: Create highlev firm dummy variable 
egen temp=xtile(leverage), nq(3) by(privateloan)
gen highlev=1 if temp==3
replace highlev=0 if highlev==. & temp!=.
drop temp

label define ll 1 "High Leverage" 0 "Low Leverage"
label values highlev ll

quietly probit perfcov c.impvol365##i.highlev pricefutby100 size mtb leverage ebitda2at logmaturity loan2at i.invgrade_comp termspread if privateloan==1, cluster(gvkey) vsquish 
eststo l1, title(Loans) 
quietly margins , dydx(impvol365) over(highlev) coeflegend post
quietly test _b[impvol365:1.highlev]=_b[impvol365:0bn.highlev]
estadd scalar chisq = r(chi2) 
estadd scalar pchi= r(p)
eststo l11, title(HighLev)
est restore l1
quietly margins highlev , at(impvol365=(0.15(0.07)0.5))
marginsplot, yline(0) name(cl11, replace) nodraw title(Predictive Margins Loans)  ytitle("Prob. of Perf. Cov. Inclusion") plot1opts(lp("l") m(o)) plot2opts(lp("--") m(t))

quietly probit perfcov c.impvol365##i.highlev pricefutby100 size mtb leverage ebitda2at logmaturity loan2at i.invgrade_comp termspread if privateloan==0, cluster(gvkey) vsquish 
eststo l2, title(Bonds)
quietly margins , dydx(impvol365) over(highlev) coeflegend post
quietly test _b[impvol365:1.highlev]=_b[impvol365:0bn.highlev]
estadd scalar chisq = r(chi2) 
estadd scalar pchi= r(p)
eststo l21, title(HighLev)
est restore l2
quietly margins highlev , at(impvol365=(0.15(0.07)0.5))
marginsplot, yline(0) name(cl12, replace) nodraw title(Predictive Margins Bonds) ytitle("Prob. of Perf. Cov. Inclusion") plot1opts(lp("l") m(o)) plot2opts(lp("--") m(t))

graph combine cl12 cl11, ycommon name(cl112, replace) nodraw iscale(*.75) 

/******Interaction with Size******/
*Size: Create small firms dummy
egen temp=xtile(atq), nq(3) by(privateloan)
gen small=1 if temp==1
replace small=0 if small==. & temp!=.
drop temp

label define sm 1 "Small Size" 0 "Large Size"
label values small sm

quietly probit perfcov c.impvol365##i.small pricefutby100 size mtb leverage ebitda2at logmaturity loan2at i.invgrade_comp termspread if privateloan==1, cluster(gvkey) vsquish 
eststo s1, title(Loans) 
quietly margins , dydx(impvol365) over(small) coeflegend post
test _b[impvol365:1.small]=_b[impvol365:0bn.small]
estadd scalar chisq = r(chi2) 
estadd scalar pchi= r(p)
eststo s11, title(small)
est restore s1
quietly margins small , at(impvol365=(0.15(0.07)0.5))
marginsplot, yline(0) name(cs11, replace) nodraw title(Predictive Margins Loans) ytitle("Prob. of Perf. Cov. Inclusion") plot1opts(lp("l") m(o)) plot2opts(lp("--") m(t))

quietly probit perfcov c.impvol365##i.small pricefutby100 size mtb leverage ebitda2at logmaturity loan2at i.invgrade_comp termspread if privateloan==0, cluster(gvkey) vsquish 
eststo s2, title(Bonds)
quietly margins , dydx(impvol365) over(small) coeflegend post
test _b[impvol365:1.small]=_b[impvol365:0bn.small]
estadd scalar chisq = r(chi2) 
estadd scalar pchi= r(p)
eststo s21, title(small)
est restore s2
quietly margins small , at(impvol365=(0.15(0.07)0.5))
marginsplot, yline(0) name(cs12, replace) nodraw title(Predictive Margins Bonds) ytitle("Prob. of Perf. Cov. Inclusion") plot1opts(lp("l") m(o)) plot2opts(lp("--") m(t))

graph combine cs12 cs11, ycommon name(cs112, replace) nodraw iscale(*.75) 

/******Interaction with Z-score******/
*Z-score: Create high default risk (low zscore) dummy variable
egen temp=xtile(z_score), nq(3) by(privateloan)
gen lowzscore=1 if temp==1
replace lowzscore=0 if lowzscore==. & temp!=.
drop temp

label define zc 1 "Low Z-Score" 0 "High Z-Score"
label values lowzscore zc

quietly probit perfcov c.impvol365##i.lowzscore pricefutby100 size mtb leverage ebitda2at logmaturity loan2at i.invgrade_comp termspread if privateloan==1, cluster(gvkey) vsquish 
eststo z1, title(Loans) 
quietly margins , dydx(impvol365) over(lowzscore) coeflegend post
test _b[impvol365:1.lowzscore]=_b[impvol365:0bn.lowzscore]
estadd scalar chisq = r(chi2) 
estadd scalar pchi= r(p)
eststo z11, title(lowzscore)
est restore z1
quietly margins lowzscore , at(impvol365=(0.15(0.07)0.5))
marginsplot, yline(0) name(cz11, replace) nodraw title(Predictive Margins Loans) ytitle("Prob. of Perf. Cov. Inclusion") plot1opts(lp("l") m(o)) plot2opts(lp("--") m(t))

quietly probit perfcov c.impvol365##i.lowzscore pricefutby100 size mtb leverage ebitda2at logmaturity loan2at i.invgrade_comp termspread if privateloan==0, cluster(gvkey) vsquish 
eststo z2, title(Bonds)
quietly margins , dydx(impvol365) over(lowzscore) coeflegend post
test _b[impvol365:1.lowzscore]=_b[impvol365:0bn.lowzscore]
estadd scalar chisq = r(chi2) 
estadd scalar pchi= r(p)
eststo z21, title(lowzscore)
est restore z2
quietly margins lowzscore , at(impvol365=(0.15(0.07)0.5))
marginsplot, yline(0) name(cz12, replace) nodraw title(Predictive Margins Bonds) ytitle("Prob. of Perf. Cov. Inclusion") plot1opts(lp("l") m(o)) plot2opts(lp("--") m(t))

graph combine cz12 cz11, ycommon name(cz112, replace) nodraw iscale(*.75) 

/******Interaction with earnings return******/
*ROA: Create lowroa firm dummy variable
egen temp=xtile(ebitda2at), nq(3) by(privateloan)
gen lowroa=1 if temp==1
replace lowroa=0 if lowroa==. & temp!=.
drop temp

label define lr 1 "Low ROA" 0 "High ROA"
label values lowroa lr

quietly probit perfcov c.impvol365##i.lowroa pricefutby100 size mtb leverage ebitda2at logmaturity loan2at i.invgrade_comp termspread if privateloan==1, cluster(gvkey) vsquish 
eststo e1, title(Loans) 
quietly margins , dydx(impvol365) over(lowroa) coeflegend post
test _b[impvol365:1.lowroa]=_b[impvol365:0bn.lowroa]
estadd scalar chisq = r(chi2) 
estadd scalar pchi= r(p)
eststo e11, title(lowroa)
est restore e1
quietly margins lowroa , at(impvol365=(0.15(0.07)0.5))
marginsplot, yline(0) name(ce11, replace) nodraw title(Predictive Margins Loans) ytitle("Prob. of Perf. Cov. Inclusion") plot1opts(lp("l") m(o)) plot2opts(lp("--") m(t))

quietly probit perfcov c.impvol365##i.lowroa pricefutby100 size mtb leverage ebitda2at logmaturity loan2at i.invgrade_comp termspread if privateloan==0, cluster(gvkey) vsquish 
eststo e2, title(Bonds)
quietly margins , dydx(impvol365) over(lowroa) coeflegend post
test _b[impvol365:1.lowroa]=_b[impvol365:0bn.lowroa]
estadd scalar chisq = r(chi2) 
estadd scalar pchi= r(p)
eststo e21, title(lowroa)
est restore e2
quietly margins lowroa , at(impvol365=(0.15(0.07)0.5))
marginsplot, yline(0) name(ce12, replace) nodraw title(Predictive Margins Bonds) ytitle("Prob. of Perf. Cov. Inclusion") plot1opts(lp("l") m(o)) plot2opts(lp("--") m(t))

graph combine ce12 ce11, ycommon name(ce112, replace) nodraw iscale(*.75) 

/******Interaction with age******/
*AGE: Create young firm dummy variable
egen temp=xtile(age), nq(3) by(privateloan)
gen young=1 if temp==1
replace young=0 if young==. & temp!=.
drop temp

label define yo 1 "Younger" 0 "Older"
label values young yo

quietly probit perfcov c.impvol365##i.young pricefutby100 size mtb leverage ebitda2at logmaturity loan2at i.invgrade_comp termspread if privateloan==1, cluster(gvkey) vsquish 
eststo a1, title(Loans) 
quietly margins , dydx(impvol365) over(young) coeflegend post
test _b[impvol365:1.young]=_b[impvol365:0bn.young]
estadd scalar chisq = r(chi2) 
estadd scalar pchi= r(p)
eststo a11, title(young)
est restore a1
quietly margins young , at(impvol365=(0.15(0.07)0.5))
marginsplot, yline(0) name(ca11, replace) nodraw title(Predictive Margins Loans) ytitle("Prob. of Perf. Cov. Inclusion") plot1opts(lp("l") m(o)) plot2opts(lp("--") m(t))

quietly probit perfcov c.impvol365##i.young pricefutby100 size mtb leverage ebitda2at logmaturity loan2at i.invgrade_comp termspread if privateloan==0, cluster(gvkey) vsquish 
eststo a2, title(Bonds)
quietly margins , dydx(impvol365) over(young) coeflegend post
test _b[impvol365:1.young]=_b[impvol365:0bn.young]
estadd scalar chisq = r(chi2) 
estadd scalar pchi= r(p)
eststo a21, title(young)
est restore a2
quietly margins young , at(impvol365=(0.15(0.07)0.5))
marginsplot, yline(0) name(ca12, replace) nodraw title(Predictive Margins Bonds) ytitle("Prob. of Perf. Cov. Inclusion") plot1opts(lp("l") m(o)) plot2opts(lp("--") m(t))

graph combine ca12 ca11, ycommon name(ca112, replace) nodraw iscale(*.75) 


esttab r11 i11 l11 s11 z11 e11 a11, b(2) noobs z star(* 0.10 ** 0.05 *** 0.01) scalars("chisq \(\chi^2\) (difference)" "pchi \(p-\)value (difference)" )  ///
 rename(0.junkr 0.unrated 1.junkr 1.unrated 0.highlev 0.unrated 1.highlev 1.unrated 0.small 0.unrated 1.small 1.unrated 0.lowzscore 0.unrated 1.lowzscore 1.unrated 0.lowroa 0.unrated 1.lowroa 1.unrated 0.young 0.unrated 1.young 1.unrated) ///
 sfmt(2 2 ) mtitles  title(Average Marginal Effects of Uncertainty Loans Sample)  label coeflabels(0.unrated "No" 1.unrated "Yes")

esttab r21 i21 l21 s21 z21 e21 a21, b(2) noobs z star(* 0.10 ** 0.05 *** 0.01) scalars("chisq \(\chi^2\) (difference)"  "pchi \(p-\)value (difference)" )  ///
 rename(0.junkr 0.unrated 1.junkr 1.unrated 0.highlev 0.unrated 1.highlev 1.unrated 0.small 0.unrated 1.small 1.unrated 0.lowzscore 0.unrated 1.lowzscore 1.unrated 0.lowroa 0.unrated 1.lowroa 1.unrated 0.young 0.unrated 1.young 1.unrated) ///
 sfmt(2 2) mtitles  title(Average Marginal Effects of Uncertainty Bonds Sample)  label coeflabels(0.unrated "No" 1.unrated "Yes")
 
 
 esttab r1 i1 l1 s1 z1 e1 a1, b(2) noobs z star(* 0.10 ** 0.05 *** 0.01) scalars("chisq \(\chi^2\) (difference)" "pchi \(p-\)value (difference)" )  ///
 rename(0.junkr 0.unrated 1.junkr 1.unrated 0.highlev 0.unrated 1.highlev 1.unrated 0.small 0.unrated 1.small 1.unrated 0.lowzscore 0.unrated 1.lowzscore 1.unrated 0.lowroa 0.unrated 1.lowroa 1.unrated 0.young 0.unrated 1.young 1.unrated) ///
 sfmt(2 2 ) mtitles  title(Average Marginal Effects of Uncertainty Loans Sample)  label coeflabels(0.unrated "No" 1.unrated "Yes") varwidth(35)

graph display cr112
graph display ci112
graph display cl112 
graph display cs112 
graph display cz112 
graph display ce112 
graph display ca112  
 

 
 
/*****************************************************************************/
/*                            Cost of debt                                   */
/*****************************************************************************/	
*Since spreads for bonds and loans are somewhat different, do only separate regressions and compare
*Report marginal effect of 1 standard deviation increase 
*Spreads is average package Allindrawn for loans, and spreads2 is max. Allindrawn is spread over libor.
*Spreads is Treasury spread for bonds in bps

replace spreads=spreads/100

quietly  regress spreads impvol365 pricefutby100 size mtb leverage ebitda2at logmaturity loan2at i.invgrade_comp termspread if privateloan==1, cluster(gvkey) vsquish 
eststo y1, title(Loans) 
quietly  regress spreads impvol365 pricefutby100 size mtb leverage ebitda2at logmaturity loan2at i.invgrade_comp termspread if privateloan==0, cluster(gvkey) vsquish 
eststo y2, title(Bonds)


*****With firms fixed effects
quietly  regress spreads impvol365 pricefutby100 size mtb leverage ebitda2at logmaturity loan2at i.invgrade_comp termspread i.gvkey1 if privateloan==1, cluster(gvkey) vsquish 
eststo y3, title(Loans) 
estadd scalar  mrg1std= _b[impvol365]*volsd
quietly  regress spreads impvol365 pricefutby100 size mtb leverage ebitda2at logmaturity loan2at i.invgrade_comp termspread i.gvkey1 if privateloan==0, cluster(gvkey) vsquish 
eststo y4, title(Bonds)
estadd scalar  mrg1std= _b[impvol365]*volsd

*****Controlling for other macros
quietly  regress spreads impvol365 pricefutby100 size mtb leverage ebitda2at logmaturity loan2at i.invgrade_comp termspread creditspread vix futret6m spret6m if privateloan==1, cluster(gvkey) vsquish 
eststo y5, title(Loans)
estadd scalar  mrg1std= _b[impvol365]*volsd 
quietly  regress spreads impvol365 pricefutby100 size mtb leverage ebitda2at logmaturity loan2at i.invgrade_comp termspread creditspread vix futret6m spret6m if privateloan==0, cluster(gvkey) vsquish 
eststo y6, title(Bonds)
estadd scalar  mrg1std= _b[impvol365]*volsd


*****With interaction
quietly  regress spreads c.impvol365##i.privateloan pricefutby100 size mtb leverage ebitda2at logmaturity loan2at i.invgrade_comp termspread i.gvkey1, cluster(gvkey) vsquish 
eststo y7, title(All) 

quietly  regress spreads c.impvol365##i.privateloan pricefutby100 size mtb leverage ebitda2at logmaturity loan2at i.invgrade_comp termspread i.gvkey1 if bothgroups==1, cluster(gvkey) vsquish 
eststo y8, title(Both) 



********Average marginal effect of a one standard deviaiton increase in price uncertainty on spread
est restore y3
quietly margins, dydx(impvol365) coeflegend post
estadd scalar y00 = _b[impvol365]*volsd*100
eststo y31, title(Loans)

est restore y4
quietly margins, dydx(impvol365) coeflegend post
estadd scalar y00 = _b[impvol365]*volsd*100
eststo y41, title(Bonds)

est restore y7
quietly margins , dydx(impvol365) over(privateloan) coeflegend post
test _b[impvol365:1.privateloan]=_b[impvol365:0bn.privateloan]
estadd scalar y01 = _b[impvol365:1.privateloan]*volsd*100
estadd scalar y02 = _b[impvol365:0bn.privateloan]*volsd*100
estadd scalar cy0 = r(F) 
estadd scalar py0= r(p)
eststo y71, title (All)
est restore y7
quietly margins , dydx(impvol365)  coeflegend post
estadd scalar y00 = _b[impvol365]*volsd*100
eststo y72, title (All)

est restore y8
quietly margins , dydx(impvol365) over(privateloan) coeflegend post
test _b[impvol365:1.privateloan]=_b[impvol365:0bn.privateloan]
estadd scalar y01 = _b[impvol365:1.privateloan]*volsd*100
estadd scalar y02 = _b[impvol365:0bn.privateloan]*volsd*100
estadd scalar cy0 = r(F) 
estadd scalar py0= r(p)
eststo y81, title (Both)
est restore y8
quietly margins , dydx(impvol365)  coeflegend post
estadd scalar y00 = _b[impvol365]*volsd*100
eststo y82, title (Both)



esttab y4 y3 y7 y8, b(2) star(* 0.10 ** 0.05 *** 0.01)  r(2) nobaselevels title("Uncertainty  and Cost of Debt") label varwidth(35) mtitles  indicate("All Controls= *invgrade_comp" "Firm F.E.= *gvkey1") ///
drop(pricefutby100 size mtb leverage ebitda2at logmaturity loan2at termspread _cons) 

esttab y41 y31 y71 y81 y72 y82, b(2) noobs z star(* 0.10 ** 0.05 *** 0.01) scalars("y00 M.E. 1std(b.p.)" "y02 M.E. 1std Bonds (b.p.)" "y01 M.E. 1std Loans (b.p.)" "cy0 \(F-\)value (difference)" "py0 \(p-\)value (difference)") ///
 sfmt(2 2 2 2 3) mtitles nonumbers title(Average Marginal Effects of Uncertainty) varwidth(35) label 



 eststo clear
/*****************************************************************************/
/*                            Hedging                                        */
/*****************************************************************************/
*Use tax convexity (taxsave) as an instrument for hedgint.
*Construct variable for tax saving from hedging following Graham_Smith_JF1999 and Campello_Lin_Ma_Zou_JF2011 (p1628)
*Tax convexity has a positive and significant on hedging.



label var l_hedgint "Hedging Intensity"
label var hedgint "Hedging Intensity"
label var l_taxsave "Tax Convexity"

gen lheg=l_hedgint
replace lheg=1 if lheg!=. & lheg>=1
label var lheg "Hedging Intensity"

*All firms
quietly probit perfcov c.impvol365##c.lheg pricefutby100 size mtb leverage ebitda2at logmaturity loan2at i.invgrade_comp termspread if privateloan==1, cluster(gvkey) vsquish 
eststo h1, title(Loans All) 
quietly probit perfcov c.impvol365##c.lheg pricefutby100 size mtb leverage ebitda2at logmaturity loan2at i.invgrade_comp termspread if privateloan==0, cluster(gvkey) vsquish 
eststo h2, title(Bonds All)

*Firms with both
quietly probit perfcov c.impvol365##c.lheg pricefutby100 size mtb leverage ebitda2at logmaturity loan2at i.invgrade_comp termspread if privateloan==1 & bothgroups==1, cluster(gvkey) vsquish 
eststo h3, title(Loans Both) 
quietly probit perfcov c.impvol365##c.lheg pricefutby100 size mtb leverage ebitda2at logmaturity loan2at i.invgrade_comp termspread if privateloan==0 & bothgroups==1, cluster(gvkey) vsquish 
eststo h4, title(Bonds Both)


esttab h2 h1 h4 h3, b(2) star(* 0.10 ** 0.05 *** 0.01) pr2(2) nobaselevels title("Uncertainty, Hedging and Debt Covenants")  ///
 drop(pricefutby100 size mtb leverage ebitda2at logmaturity loan2at termspread _cons) label varwidth(40) mtitles indicate("All Controls= *invgrade_comp")


 
*Marginal effects
est restore h1
margins , dydx(impvol365) at(lheg=(0(0.1)1))  post
eststo h11, title(loans All)
marginsplot, name(h11, replace) plotopts(recast(line) lcolor(maroon) lp("_-_")) yline(0, lwidth(vthin) lcolor(gs11)) xlabel(0(0.5)1) ///
  ciopts(recast(rline) lpattern(dash) lcolor(maroon)) title("Loans") nodraw

est restore h2
margins , dydx(impvol365) at(lheg=(0(0.1)1)) post 
eststo h21, title(bonds All)
marginsplot, name(h21, replace) recast(line) yline(0, lwidth(vthin) lcolor(gs11)) ytitle("Prob. of Perf. Cov. Inclusion") xlabel(0(0.5)1) ///
  ytitle("Prob. of Perf. Cov. Inclusion")  ciopts(recast(rline) lpattern(dash)) title("Bonds")  nodraw

est restore h3
margins , dydx(impvol365) at(lheg=(0(0.1)1)) post 
eststo h31, title(loans Both)
marginsplot, name(h31, replace) plotopts(recast(line) lcolor(maroon) lp("_-_")) yline(0, lwidth(vthin) lcolor(gs11)) xlabel(0(0.5)1) ///
  ciopts(recast(rline) lpattern(dash) lcolor(maroon)) title("Loans") nodraw

est restore h4
margins , dydx(impvol365) at(lheg=(0(0.1)1)) post 
eststo h41, title(bonds Both)
marginsplot, name(h41, replace) recast(line) yline(0, lwidth(vthin) lcolor(gs11)) ytitle("Prob. of Perf. Cov. Inclusion") xlabel(0(0.5)1) ///
  ytitle("Prob. of Perf. Cov. Inclusion")  ciopts(recast(rline) lpattern(dash)) title("Bonds")  nodraw

  

esttab h21 h11 h41 h31,  b(2) star(* 0.10 ** 0.05 *** 0.01) r(2) pr2(2) mtitles  label title("A.M.E. of Uncertainty at various level of Hedging 0(0.1)1")

graph combine h21 h11, title("Predictive Margins: All firms") name(mh1, replace)
graph combine h41 h31, title("Predictive Margins: Firms with Both Securiies") name(mh2, replace)


 
*Predictive margins at various level of hedging 
est restore h1 
margins, at(impvol365=(0.15(0.07)0.5) lheg=(0 0.25 0.5 0.75 1))
marginsplot, ytitle("Prob. of Perf. Cov. Inclusion") title("Loans") legend(on order(1 "Hedging 0%" 2 "Hedging 25%" 3 "Hedging 50%" 4 "Hedging 75%"5 "Hedging 100%")) name(h1, replace) nodraw

est restore h2 
margins, at(impvol365=(0.15(0.07)0.5) lheg=(0 0.25 0.5 0.75 1))
marginsplot, ytitle("Prob. of Perf. Cov. Inclusion") title("Bonds") legend(on order(1 "Hedging 0%" 2 "Hedging 25%" 3 "Hedging 50%" 4 "Hedging 75%"5 "Hedging 100%")) name(h2, replace) nodraw

est restore h3 
margins, at(impvol365=(0.15(0.07)0.5) lheg=(0 0.25 0.5 0.75 1))
marginsplot, ytitle("Prob. of Perf. Cov. Inclusion") title("Loans") legend(on order(1 "Hedging 0%" 2 "Hedging 25%" 3 "Hedging 50%" 4 "Hedging 75%"5 "Hedging 100%")) name(h3, replace) nodraw

est restore h4 
margins, at(impvol365=(0.15(0.07)0.5) lheg=(0 0.25 0.5 0.75 1))
marginsplot, ytitle("Prob. of Perf. Cov. Inclusion") title("Bonds") legend(on order(1 "Hedging 0%" 2 "Hedging 25%" 3 "Hedging 50%" 4 "Hedging 75%"5 "Hedging 100%")) name(h4, replace) nodraw

graph combine h2 h1, name(mh1, replace) title("Predictive Margins: All firms",size(medlarge)) iscale(*.75)
graph combine h4 h3, name(mh2, replace) title("Predictive Margins: Firms with Both Securities",size(medlarge)) iscale(*.75)
 



*IV All firms
quietly regress l_hedgint l_taxsave impvol365 pricefutby100 size mtb leverage ebitda2at logmaturity loan2at i.invgrade_comp termspread, cluster(gvkey) vsquish 
eststo h0, title( hedging) 
predict l_hedgint_hat if e(sample)
label var l_hedgint_hat "Hedging Intensity"

quietly probit perfcov c.impvol365##c.l_hedgint_hat pricefutby100 size mtb leverage ebitda2at logmaturity loan2at i.invgrade_comp termspread if privateloan==1, cluster(gvkey) vsquish 
eststo h3, title(IV Loans) 
quietly probit perfcov c.impvol365##c.l_hedgint_hat pricefutby100 size mtb leverage ebitda2at logmaturity loan2at i.invgrade_comp termspread if privateloan==0, cluster(gvkey) vsquish 
eststo h4, title(IV Bonds)

*drop l_hedgint_hat

*IV Firms with both
quietly regress l_hedgint l_taxsave impvol365 pricefutby100 size mtb leverage ebitda2at logmaturity loan2at i.invgrade_comp termspread if bothgroups==1, cluster(gvkey) vsquish 
eststo h0, title(IV hedging) 
predict l_hedgint_hat if e(sample)
label var l_hedgint_hat "Hedging Intensity"

quietly probit perfcov c.impvol365##c.l_hedgint_hat pricefutby100 size mtb leverage ebitda2at logmaturity loan2at i.invgrade_comp termspread if privateloan==1 & bothgroups==1, cluster(gvkey) vsquish 
eststo h3, title(IV Loans) 
quietly probit perfcov c.impvol365##c.l_hedgint_hat pricefutby100 size mtb leverage ebitda2at logmaturity loan2at i.invgrade_comp termspread if privateloan==0 & bothgroups==1, cluster(gvkey) vsquish 
eststo h4, title(IV Bonds)

*drop l_hedgint_hat

esttab h2 h1 h0 h4 h3, b(2) star(* 0.10 ** 0.05 *** 0.01) r(2) pr2(2) nobaselevels title("Uncertainty, Hedging and Debt Covenants") rename(l_hedgint_hat l_hedgint c.impvol365#c.l_hedgint_hat c.impvol365#c.l_hedgint) ///
 drop(pricefutby100 size mtb leverage ebitda2at logmaturity loan2at termspread _cons) label varwidth(40) mtitles indicate("All Controls= *invgrade_comp")

 
 


 
 
 
 
 
 
 
 
 






